import matplotlib.pyplot as plt
import pandas as pd

# 读取CSV文件
df = pd.read_csv('bilibili_videos.csv', encoding='utf-8')

# 找出播放量前十的up主
top_10_up_main = df.groupby('up主')['投币数'].sum().nlargest(10)

# 计算前十up主的播放量占比
total_play_count = top_10_up_main.sum()
percentages = top_10_up_main / total_play_count

# 绘制扇形图
plt.rcParams['font.sans-serif']=['SimHei']
plt.figure(figsize=(8, 8))
plt.pie(percentages, labels=percentages.index, autopct='%1.1f%%', startangle=140, colors=plt.cm.tab20.colors)
plt.axis('equal')  # 使饼图比例相等
plt.title('Top 10 Up主播放量占比')
plt.show()
